package java8.lambda.utility;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiPredicate;

public class LRUCache<K, V> extends LinkedHashMap<K, V> {
    private static final long serialVersionUID = 1L;

    private BiPredicate<Map<K,V>, Map.Entry<K,V>> biPredicate;

    public LRUCache(int maxSize) {
        this(maxSize, 16, 0.75F, false);
    }

    public LRUCache(int maxSize, int initialCapacity, float loadFactor, boolean accessOrder) {
        super(initialCapacity, loadFactor, accessOrder);
        biPredicate= (mapa,entity) -> mapa.size()>maxSize;
    }

    protected boolean removeEldestEntry(Entry<K, V> eldest) {
        return biPredicate.test(this,eldest);
    }
}
